//
//  Rx+concat.swift
//  SwiftCode
//
//  Created by yuhus on 2023/10/30.
//

import RxSwift

/// concat 操作符将多个 Observables 按顺序串联起来，当前一个 Observable 元素发送完毕后，后一个 Observable 才可以开始发出元素。
///
/// - 测试：只有当 subject1 调用 onCompleted 后，subject2 发出的元素才会被订阅
func concatRx() {
  let subject1 = PublishSubject<String>()
  let subject2 = PublishSubject<String>()
  
  _ = subject1.concat(subject2)
    .subscribe { Timber.d($0) }
    
  subject1.onNext("subject1 onNext 1")
  subject2.onNext("subject2 onNext 1")
  
  subject1.onNext("subject1 onNext 2")
  subject2.onNext("subject2 onNext 2")
  
  subject1.onCompleted()
  
  subject1.onNext("subject1 onNext 3")
  subject2.onNext("subject2 onNext 3")
}
